<template>
    <el-dialog title="拒审原因" :visible.sync="rejectData.dialogState" size="tiny"  class="dialog-box"  @close="close('dataForm')" >
        <el-form v-loading='loading' class="form-content"  :model="dataForm" :rules="rules" ref="dataForm" label-width="0px"  label-position='left'>
            <el-row :gutter="21" class="school-item">
                <el-col :span="24">
                    <el-form-item label="" prop="reason" :rules="rules.reason">
                        <el-popover
                        placement="top-start"
                        trigger="focus" 
                        content="长度在30个字符以内。">
                            <el-input type="textarea" :rows="4" slot="reference" :maxlength="30" placeholder="请输入内容" v-model="dataForm.reason"></el-input>
                        </el-popover>
                    </el-form-item>
                </el-col>
            </el-row>
            <p><font color='red'>* </font>此操作不可逆，还请谨慎操作。</p>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="resetForm('dataForm')"> 取 消 </el-button>
            <el-button type="primary" @click="submitForm('dataForm')"> 确 定 </el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { updateSettlement } from 'api/settleManagement';
    export default {
        props: {
            rejectData: {
                default() {
                    return {
                        dialogState: false,
                        settlementIds: null,
                        status: ''
                    }
                },
                required: true
            }
        },
        data() {
            return {
                loading: false,
                dataForm: {
                    reason: ''
                },
                rules: {
                    reason: [
                        { required: true, message: '内容不能为空', trigger: 'blur' },
                        { min: 1, max: 30, message: '长度在30个字符以内', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            submitForm(dataForm) {
                this.$refs[dataForm].validate((valid) => {
                    if (valid) {
                        // let status = '2'; // 1:通过  2：完成  3：驳回  4：失败”,
                        let status = this.rejectData.status; // 记录对应status”  
                        let auditDesc = this.dataForm.reason;
                        this.loading = true;
                        updateSettlement(this.rejectData.settlementIds, status, auditDesc).then(response => {
                            this.loading = false;

                            if (response.data.status == 200) {
                                this.$message.success(response.data.errorMsg);
                                this.rejectData.dialogState = false;
                                this.$emit('search');
                                this.dataForm.reason = '';
                            } else {
                                this.$message.error(response.data.errorMsg);
                            }
                        }).catch(() => {
                            this.loading = false;
                        })
                    }
                })
            },
            resetForm(dataForm) {
                this.rejectData.dialogState = false;
                this.$refs[dataForm].resetFields();
            },
            close(dataForm) {
                this.rejectData.dialogState = false;
                this.$refs[dataForm].resetFields();
            }
        }
    }

</script>

<style lang="scss" scoped>
    .dialog-box{
        .form-content{
            width: 80%;
            margin: 0 auto; 
        }
        .dialog-footer{
            width: 80%;
            margin: 0 auto; 
            text-align:center;
        }
    }
</style>